home *** CD-ROM | disk | FTP | other *** search
- Path: news.informatik.uni-muenchen.de!usenet
- From: Kurt Watzka <watzka@stat.uni-muenchen.de>
- Newsgroups: comp.lang.c
- Subject: Re: #including everything
- Date: Fri, 12 Apr 1996 19:48:04 +0200
- Organization: Institut fⁿr Statistik
- Message-ID: <316E9754.237@stat.uni-muenchen.de>
- References: <829297481snz@setch.demon.co.uk>
- NNTP-Posting-Host: pc4.stat.uni-muenchen.de
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (WinNT; I)
-
- Mark Setchell wrote:
- >
- > Does anyone have an opinion about how sensible it is to #include all
- > standard system header files in C programs? I work on a project with
- > approximately 2000 files and 500,000 lines of code and every file
- > has a long piece at the start like this:
- >
- > #include <stdio.h>
- > #include <errno.h>
- > #if !defined(SGI) && !defined(HPUX)
- > #include <x.h>
- > #else
- > #if !defined(IBM_R2) && !defined(CRAY)
- > #include <y.h>
- > #endif
- > #endif
- >
- > This is obviously a maintenance nightmare, porting is no fun either. I
- > am thinking of making a single include file with all system headers in
- > it (i.e. ones in <> as opposed to those in "").
-
- A reasonable approach if all your compilation units use all "system" header
- files, _but_ this is the main reason for this problem, anyway.
-
- Portable programs can be designed so that system specific stuff happens
- in system specific compilation units, whereas portable stuff happens in
- potable compilation units.
-
- A compilation unit designed for POSIX directory access can use <unistd.h>
- without a bad conscience, whereas the implementation of a general purpose
- "key to value" map can use "standard" header files without any need to
- access system specific headers, because it simply does not need the
- additional features provided by them.
-
- The "long list of headers at the beginning of each file"-problem usually
- is a result of a bad modularization. In most cases, you should not need
- that long list of "system" headers.
-
- > I suspect the disadvantages are:
- > 1) If it changes, all files have to be rebuilt - but that's ok it won't
- > change often
- > 2) It may bloat the size of the binaries by including unused variables,
- > but that's not really a problem on Virtual Memory machines, and the
- > increase in size isn't much anyway.
-
- If you _define_ variables in a header file, you do have a problem, and the
- problem is not increasing code size when the header is included in
- numerous compilation units.
-
- Including all possible header files might add some symbol information to
- your executable, but the additional size should not survive "strip" or a
- "release build".
-
- > 3) ???
- >
- > Weighed against this, the advantages are:
- > 1) porting and maintenance become easier with only one file to maintain
-
- I stronly disagree with this. There may be some "services" that have
- to include a system specific header file in the header file that provides
- the interface to that "service", but in general, non-portable includes
- should happen in non-portable compilation units.
-
- > 2) all system calls/functions are guaranteed to be prototyped
-
- If your compiler does not support "forcing" prototypes for functions,
- you should think about changing your tool.
-
- > Also, which system files should I #include?
-
- In each compilation unit, the files needed by that compilation unit and
- no others.
-
- Kurt
-